<template>
  <div>
    <el-button type="success" size="mini" style="margin-right: 1000px;margin-bottom: 10px;" @click="back">返回</el-button>
    <el-row>
      <el-col :span="17">
        <div class="block">
          <el-carousel trigger="click" height="300px">
            <el-carousel-item v-for="item in this.otherImgList" :key="item">
              <el-image style="width:100%;height: 100%; " :src="item">
              </el-image>
            </el-carousel-item>
          </el-carousel>
        </div>
      </el-col>

      <el-col :span="6" style="text-align: left; margin-left: 18px;">
        <h1 style="font-weight: bold; font-size: 18px; color: #303133;">
          保险名：<b style="color: #409EFF;">{{ title }}</b>
        </h1>

        <p style="margin: 20px 0;">
          <span style="font-weight: bold;  color: #303133;">保险价格：</span>
          <b style="color: red;">{{ price }} ￥</b> <span>/每年</span>
        </p>
        <p>
          <span style="font-weight: bold;  color: #303133;">保险类型：</span>
          <span v-if="type == 0">意外险</span>
          <span v-else-if="type == 1">重疾险</span>
          <span v-else-if="type == 2">旅游险</span>
          <span v-else-if="type == 3">医疗险</span>
          <span v-else>养老险</span>
        </p>
        <p style="margin: 20px 0;">
          <span style="font-weight: bold;  color: #303133;">保险价公司：</span>
          <span v-if="insuranceCompany == 0">人寿保险</span>
          <span v-else-if="insuranceCompany == 1">健康平安</span>
          <span v-else-if="insuranceCompany == 2">太平洋保险</span>
          <span v-else>一生无忧</span>
        </p>
        <el-button size="medium" type="success" @click="toInsuarnce()">保险预订</el-button>
        <span style="margin-left: 10px;">
          <i class="el-icon-star-on" v-if="isCollect" @click="collected"></i>
          <i class="el-icon-star-off" v-else @click="collected"></i>
        </span>
      </el-col>
    </el-row>

    <el-row style="width: 100%; display: block; float: left; margin-top: 30px;margin-bottom: 30px;">
    </el-row>

    <el-row>
      <el-col :span="16">
        <div class="grid-content bg-purple">
          <el-card class="box-card" style="width: 99%;padding: 12px;">
            <div slot="header" class="clearfix">
              <span style="font-weight: bold; color: green; font-size: 25px;"><i class="el-icon-notebook-2"></i>
                保险简介</span>
            </div>
            <div class="item">
              <p class="textHead"><i class="el-icon-time"></i> 保险期限</p>
              <div class="textBody">一年</div>
            </div>
            <div class="item">
              <p class="textHead"><i class="el-icon-notebook-1"></i> 保险介绍 <i class="el-icon-right"></i></p>
              <div class="textBody">{{ resume }}</div>
            </div>
          </el-card>
        </div>
      </el-col>
      <el-col :span="16">
        <div class="grid-content bg-purple">
          <el-card class="box-card" style="width: 99%;">
            <div slot="header" class="clearfix">
              <span style="font-weight: bold; color: green; font-size: 25px;"><i class="el-icon-warning-outline"></i>
                保险预定事项</span>
            </div>

            <div style="padding: 10px;">
              <span class="textHead"><i class="el-icon-user"></i> 适用人群</span><br />
              <div class="textBody" v-if="type != 4">3-65周岁</div>
              <div class="textBody" v-if="type == 4">65-100周岁</div>
              <br />
              <span class="textHead"><i class="el-icon-postcard"></i> 保单形式</span><br />
              <div class="textBody">电子保单 纸质保单</div>
              <br />
              <span class="textHead"><i class="el-icon-warning"></i> 投保须知</span><br />
              <div class="textBody">
                1、本保险每位被保险人限投一份，多投无效。
              </div>
              <div class="textBody">
                2、本保险意外伤害医疗保险责任及高风险运动意外医疗责任绝对免赔额为300元。
              </div>

              <div class="textBody">
                3、本保险意外伤害住院津贴责任免赔天数有3天。
              </div>
            </div>
          </el-card>
        </div>
      </el-col>
    </el-row>
  </div>
</template>

<script>
import newAxios from "../../utils/axios";
export default {
  data() {
    return {
      title: "",
      imgUrl: "",
      spotAddress: "",
      price: 0.0,
      linkPhone: "",
      resume: "",
      type: 1,
      setoffTime: 0,
      insuranceCompany: "",
      isCollect: false,
      myInfo: {},
      otherImgList: []
    };
  },
  created() {
    this.getHotelData();
    this.Collect();
    this.getUser();
  },
  methods: {
    getUser() {
      newAxios
        .get("/admin/findUserById")
        .then((res) => res.data)
        .then((res) => {
          if (res.code == 200) {
            console.log(res.data);
            this.myInfo = res.data;
          }
        })
        .catch((err) => {
          this.$message = "正在加载ing...有事请留言";
        });
    },
    toInsuarnce() {
      if (Object.keys(this.myInfo).length > 0) {
        this.$router.push({
          path: "/insuranceOrder",
          query: {
            insuranceId: this.$route.query.insuranceId,
            price: this.price,
          },
        });
      } else {
        this.$message.error("请先登录！");
      }

    },
    toSpotOrder() {
      this.$router.push({
        path: "/routeOrder",
        query: {
          routeId: this.$route.query.insuranceId,
          price: this.price,
        },
      });

    },
    //判断是否收藏
    Collect() {
      newAxios
        .get("/collection/isCollection", {
          params: {
            productId: parseInt(this.$route.query.insuranceId),
            productType: 4,
          },
        })
        .then((res) => res.data)
        .then((res) => {
          console.log(res);
          if (res.code == 200) {
            this.isCollect = res.data;
            this.getHotelData();
          } else {
            this.isCollect = res.data;
            this.getHotelData();
          }
        });
    },
    //收藏

    collected() {
      newAxios
        .post("/collection/save", {
          productId: parseInt(this.$route.query.insuranceId),
          productType: 4,
          title: this.title,
        })
        .then((res) => res.data)
        .then((res) => {
          console.log(res.data);
          if (res.code == 200) {
            this.Collect();
            this.getHotelData();
            if (res.data == true) {
              this.$message({
                message: '收藏成功',
                type: 'success'
              })
            } else {
              this.$message({
                message: '收藏取消',
                type: 'warning'
              })
            }
          } else {
            this.Collect();
            this.getHotelData();
          }
        });
    },
    back() {
      this.$router.back();
    },
    getHotelData() {
      console.log(this.$route.query.insuranceId);
      newAxios
        .get("/insurance/findInsuranceById", {
          params: {
            id: this.$route.query.insuranceId,
          },
        })
        .then((res) => {
          console.log(res.data.data);
          this.title = res.data.data.title;
          this.imgUrl = res.data.data.imgUrl;
          this.price = res.data.data.price;
          this.resume = res.data.data.resume;
          this.type = res.data.data.type;
          this.insuranceCompany = res.data.data.insuranceCompany;
          this.otherImgList = res.data.data.otherUrl.split(",");
        });
    },
  },
};
</script>

<style>
.text {
  font-size: 14px;
}

.item {
  margin-bottom: 18px;
}

.textBody {
  width: 100%;
  line-height: 25px;
  font-size: 18px;
  padding: 10px;
}

.clearfix:before,
.clearfix:after {
  display: table;
  content: "";
}

.clearfix:after {
  clear: both;
}

.box-card {
  width: 480px;
}

.el-carousel__item h3 {
  color: #475669;
  font-size: 14px;
  opacity: 0.75;
  line-height: 150px;
  margin: 0;
}

.el-carousel__item:nth-child(2n) {
  background-color: #99a9bf;
}

.el-carousel__item:nth-child(2n + 1) {
  background-color: #d3dce6;
}
</style>
